package module.main.view.mainInterface.operatepanel
{
	import code.ui.SimpleToolTips;
	import code.utils.MaterialUtil;
	
	import com.darwin.darwinMVC.core.CommonData;
	import com.darwin.darwinUI.containers.Box;
	import com.darwin.darwinUI.containers.ContainerBase;
	import com.darwin.darwinUI.controls.Label;
	import com.darwin.darwinUI.controls.LabelButton;
	import com.darwin.darwinUI.core.UIComponent;
	import com.darwin.darwinUI.manager.ToolTipManager;
	import com.darwin.darwinUI.manager.UIManager;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import module.building.view.buildingUpPanel.BuildingUpTabView;
	import module.edittroop.view.troopinfopanel.EditTroopPanel;
	import module.main.event.MainEvent;
	import module.main.view.MainView;
	import module.main.view.ResourceConst;
	import module.main.view.mainInterface.friendListPanel.FriendListPanel;

	public class OperateFriendSango extends UIComponent
	{
		private var uicommand:UIComponent;
		/**
		 *按钮背景 
		 */		
		private var _buttonBg:Sprite;
		private var _friendButton:LabelButton;
		private var _sangoButton:LabelButton;
		private var friendListIsOpen:Boolean = false;
		private var friendListPanel:FriendListPanel;
		
		public function OperateFriendSango()
		{
			uicommand = new UIComponent();
			this.addChild(uicommand);
			_buttonBg = MaterialUtil.getPreloadMaterial("main",ResourceConst.OPERATE_FT_BUTTON_BACKGROUND) as Sprite;
			uicommand.addChild(_buttonBg);
			this.height = _buttonBg.height;
			this.width = _buttonBg.width;
			
			_friendButton = new LabelButton();
			_friendButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_FRIEND;
			_friendButton.backgroundAuto = true;
			
			_sangoButton = new LabelButton();
			_sangoButton.backgroundSkin = ResourceConst.OPERATE_PLAYER_SANGO_ICON;
			_sangoButton.backgroundAuto = true;
			setView();
		}
		
		private function setView():void
		{
			_friendButton.x = 18;
			_friendButton.y = 3;
			uicommand.addChild(_friendButton);
			_friendButton.addEventListener(MouseEvent.CLICK, clickHandler);
			_friendButton.addEventListener(MouseEvent.MOUSE_MOVE,moveHandle);
			
			_sangoButton.x = 70;
			_sangoButton.y = 3;
			uicommand.addChild(_sangoButton);
			_sangoButton.addEventListener(MouseEvent.CLICK,clickHandler);
			_sangoButton.addEventListener(MouseEvent.MOUSE_MOVE,moveHandle);
		}
		private function moveHandle(e:MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case _friendButton:
					UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"好友",ToolTipManager.UP);
					break;
				case _sangoButton:
					UIManager.getToolTipManager().showTips(SimpleToolTips,e.target,"武将",ToolTipManager.UP);
					break;
			}
		}
		private function clickHandler(e:MouseEvent):void
		{
			switch(e.currentTarget)
			{
				case _sangoButton:
					//var $editTroopPanel:EditTroopPanel = new EditTroopPanel();
//					var $popEvent:MainEvent = new MainEvent(MainEvent.POP_UP_TROOP_INFO_PANEL);
//					this.dispatchEvent($popEvent);
					
					dispatchEvent(new MainEvent(MainEvent.CLICK_TROOPLIST_EVENT));
					//UIManager.getPopUpManager().addPopUp(EditTroopPanel.getInstance());
					break;
				case _friendButton:
					dispatchEvent(new MainEvent(MainEvent.CLICK_FRIEND_EVENT, true, true));
					break;
				default:
					break;
			}
		}
		
		private function openOrCloseFriendList():void
		{
			if(!friendListIsOpen)
			{
				friendListPanel = new FriendListPanel();
				friendListPanel.data = MainView.getInstance().friendList;
				uicommand.addChild(friendListPanel);
				friendListPanel.x = -33;
				friendListPanel.y = -288;
				friendListIsOpen = true;
			}
			else
			{
				friendListIsOpen = false;
				friendListPanel.removeAllChild();
				uicommand.removeChild(friendListPanel);
			}
//			var friendListPanel:FriendListPanel = new FriendListPanel();
		}
	}
}